<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<script type="text/javascript" src="<c:url value="/layout/javascript/jquery.bgiframe.js"/>">/**/</script>
<script type="text/javascript" src="<c:url value="/layout/javascript/jquery.form.js"/>">/**/</script>
<script type="text/javascript" src="<c:url value="/layout/javascript/form.js"/>">/**/</script>
<script type="text/javascript" src="<c:url value="/layout/javascript/form.admin.js"/>">/**/</script>

<script type="text/javascript">
// Messaggio da visualizzare in caso di username già utilizzato
var msgOpts = {
    msg : "<bean:message key="user.add.msg" bundle="errors"/>",
    boxTitle : "<bean:message key="user.add.boxTitle" bundle="errors"/>",
    msgStatus: "<bean:message key="user.add.msgStatus" bundle="errors"/>"
};

// Messaggio da visualizzare in caso di errore nella chiamata a checkForDupUsername(...)
var errorOpts = {
	    msg : "<bean:message key="user.add.err.msg" bundle="errors"/>",
	    boxTitle : "<bean:message key="user.add.err.boxTitle" bundle="errors"/>",
	    msgStatus: "<bean:message key="user.add.err.msgStatus" bundle="errors"/>"
};

$(document).ready(function() {
	var options = { 
            target:    '#validationbox', 
            beforeSubmit: function() {
		                        $('#validationbox').html('<img alt="<bean:message key="saving.message"/>" src="<c:url value="/layout/images/ajax-loader.gif"/>"/><bean:message key="saving.message"/>');
                                $('#validationbox').dialog('open');
		                        var result = checkForDupUsername('${pageContext.request.contextPath}/admin/checkfordupusername.do', $('#username'));
		                        if (result) {
		                        	$('#validationbox').dialog('close');
		                        }
								return !result;
		                  },
            error:     function () {
		                   $('#validationbox').dialog('close');
                           showErrorDialog('#dialog', 
                                       { msg: "<bean:message key="user.submit.form.msg" bundle="errors"/>",
                                         boxTitle: "<bean:message key="user.submit.form.boxTitle" bundle="errors"/>",
                                         msgStatus: "<bean:message key="user.submit.form.msgStatus" bundle="errors"/>" });
                      }  
    };
    
    $('#form_11691').ajaxForm(options);
    
	$('#username').blur(function() {
		checkForDupUsername('${pageContext.request.contextPath}/admin/checkfordupusername.do', $(this));
	});
});
</script>

<div id="content">
        <!--FORM-->
        <fieldset id="fieldset">
            <legend class="fieldsetLabel"><bean:message key="user.account" bundle="profile"/></legend>
                
            <div id="form_container">
                <html:form styleId="form_11691" styleClass="appnitro" action="${requestScope.action}"> 
                
                    <ul>
                    <li id="li_5" >
                        <label class="description" for="username"><bean:message key="user.username" bundle="profile"/></label>
                        <div>
                            <html:text property="username" styleId="username" styleClass="element text medium" maxlength="255" />
                            <html:checkbox property="enabled"><bean:message key="user.enableaccount" bundle="profile"/></html:checkbox> 
                        </div> 
                    </li>       
                    <li id="li_7profile" >
                        <label class="description" for="element_7"><bean:message key="user.password" bundle="profile"/></label>
                        <div>
                            <html:password property="password" styleId="element_7"  styleClass="element text large" maxlength="255" /> 
                        </div> 
                    </li>       
                    <li id="li_6profile" >
                        <label class="description" for="element_6"><bean:message key="user.confirmpassword" bundle="profile"/></label>
                        <div>
                            <html:password property="cPassword" styleId="element_6" styleClass="element text medium" maxlength="255" /> 
                        </div> 
                    </li>   
                    <li id="li_10Profile" >
                        <label class="description" for="element_10"><bean:message key="user.role" bundle="profile"/></label>
                        <div>
                            <html:select property="roleName" styleClass="element select large" styleId="element_10"> 
                                <html:options collection="roles" property="name" labelProperty="description"/>
                            </html:select>
                        </div>
                    </li>
                    <li id="li_9Profile" >
						<label class="description" for="element_9"><bean:message key="user.office" bundle="profile"/></label>
						<div>
							<html:select property="officeID" styleClass="element select large" styleId="element_9"> 
								<html:options collection="offices" property="officeID" labelProperty="number"/>
							</html:select>
						</div> 
					</li>	
                    <li id="li_2Profile" >
                        <label class="description" for="element_2"><bean:message key="user.email" bundle="profile"/></label>
                        <div>
                            <html:text property="email" styleId="element_2Profile"  styleClass="element text medium" maxlength="255" /> 
                        </div> 
                    </li>       
                    <li class="buttons">
                        <html:hidden property="userID" styleId="userID"/>
                        <html:submit property="saveForm" styleId="saveForm" styleClass="button_text">
                            <bean:message key="profile.button.submit" bundle="profile"/>
                        </html:submit>
                    </li>
                    </ul>
                </html:form>    
            </div>              
        </fieldset> 
</div>